﻿using HCQ2_IBLL;
using HCQ2_Model.VRDD.InputDto._210908;
using HCQ2_Model.VRDD.OutputDto._210908;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace HCQ2_BLL
{
    public partial class T_VRDDStoreTypeUserBLL: IT_VRDDStoreTypeUserBLL
    {
        /// <summary>
        ///  获取店铺数据字典类别列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<OutputStoreDictType> GetDictTypeByStore(InputStoreDictType param)
        {
            return DBSession.IT_VRDDStoreTypeUserDAL.GetDictTypeByStore(param);
        }
        /// <summary>
        ///  获取人员详情
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<OutputStoreUserInfo> GetStoreUserInfo(InputStoreUserInfo param)
        {
            var list= DBSession.IT_VRDDStoreTypeUserDAL.GetStoreUserInfo(param);
            list?.ForEach(s => {
                if (!string.IsNullOrEmpty(s.userImg))
                    s.userImg = s.userImg.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
            });
            return list;
        }
        /// <summary>
        ///  获取店铺类别人员列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<OutputGetStoreTypeUser> GetStoreTypeUser(InputGetStoreTypeUser param)
        {
            var list= DBSession.IT_VRDDStoreTypeUserDAL.GetStoreTypeUser(param);
            list?.ForEach(s => { 
                if(!string.IsNullOrEmpty(s.userImg))
                    s.userImg= s.userImg.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
            });
            return list;
        }
        /// <summary>
        ///  获取店铺商品列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<OutputStoreGoodList> GetStoreGoodList(InputStoreGoodList param)
        {
            var list = DBSession.IT_VRDDStoreTypeUserDAL.GetStoreGoodList(param);
            list?.ForEach(s=> {
                //规格数量
                if (!string.IsNullOrEmpty(s.specOption))
                    s.specNum = s.specOption.Trim(',').Split(',').Count();
                //横向缩略图
                if(!string.IsNullOrEmpty(s.fileImage))
                    s.fileImage = s.fileImage.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
                //计算0级折扣价
                if (s.rate0 > 0)
                    s.ratePrice = Math.Round(s.filePrice * s.rate0 / 10, 1);
                else
                    s.ratePrice = s.filePrice;
            });
            return list;
        }
        /// <summary>
        ///  获取商品类别目录
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<OutputFolderType> GetGoodsFolderType(InputFolderType param)
        {
            var list = DBSession.IT_VRDDStoreTypeUserDAL.GetGoodsFolderType(param);
            list?.ForEach(s =>
            {
                if(!string.IsNullOrEmpty(s.FolderImage))
                    s.FolderImage= s.FolderImage.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
            });
            return list;
        }
        /// <summary>
        ///  获取被删除的目录下是否存在已上架的商品
        /// </summary>
        /// <param name="folder_id"></param>
        /// <returns></returns>
        public bool GetGoodsFolderTypeNum(int folder_id)
        {
            int num = DBSession.IT_VRDDStoreTypeUserDAL.GetGoodsFolderTypeNum(folder_id);
            return num > 0 ? true : false;
        }
        /// <summary>
        ///  获取我服务的店铺
        /// </summary>
        /// <param name="param"></param>
        /// <param name="user_id">用户id</param>
        /// <returns></returns>
        public List<OutputByMyServe> GetStoreByMyServe(InputByMyServe param, int user_id)
        {
            var list = DBSession.IT_VRDDStoreTypeUserDAL.GetStoreByMyServe(param, user_id);
            list?.ForEach(s =>
            {
                if(!string.IsNullOrEmpty(s.FolderImage))
                    s.FolderImage= s.FolderImage.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
            });
            return list;
        }
    }
}